local youdi = fk.CreateSkill({
    name = "sj3__youdi",
})

Fk:loadTranslationTable{
  ["sj3__youdi"] = "诱敌",
  [":sj3__youdi"] = "你可以跳过一个阶段并拼点，若你赢，你对本回合拼点赢过的角色各造成1点伤害。",
  
  ["$sj3__youdi1"] = "无名小卒，可敢再前进一步！",
  ["$sj3__youdi2"] = "予以小利，必有大获。",
  
  
  ["#sj3__youdi"] = "诱敌：你可以跳过%arg阶段并拼点，若你赢，你对本回合拼点赢过的角色各造成1点伤害",
  ["@sj3__youdi-turn"] = "诱敌",
}

youdi:addEffect(fk.EventPhaseChanging, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(youdi.name)
    and table.contains({Player.Start,Player.Judge, Player.Draw, Player.Play, Player.Discard, Player.Finish}, data.phase)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local t = table.filter(room:getOtherPlayers(player),function (p)
      return player:canPindian(p)
    end)
    if #t > 0 then
      local ps, cards, success = room:askToChooseCardsAndPlayers(player,{
        targets = t,
        min_num = 1,
        max_num = 1,
        min_card_num = 1,
        max_card_num = 1,
        pattern = ".|.|.|hand|.|.|.",
        skill_name = youdi.name,
        prompt = "#sj3__youdi:::"..Util.PhaseStrMapper(data.phase),
      })
      if success then
        event:setCostData(self,{p = ps[1],cid = cards[1]})
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    data.skipped = true
    local room = player.room
    local costdata = event:getCostData(self)
    local pindian = player:pindian({costdata.p},youdi.name,Fk:getCardById(costdata.cid))
    if pindian.results[costdata.p].winner == player then
      for _, p in ipairs(room:getAlivePlayers()) do
        if p:getMark("@sj3__youdi-turn") ~= 0 and not p.dead then
          room:damage{
            from = player,
            to = p,
            damage = 1,
            skillName = youdi.name,
          }
        end
      end
    end
  end,
})

youdi:addEffect(fk.PindianFinished, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(youdi.name) and player.phase ~= Player.NotActive
  end,
  on_refresh = function(self, event, target, player, data)
    for _, r in pairs(data.results) do
      if r.winner then
        player.room:setPlayerMark(r.winner,"@sj3__youdi-turn","pindianwin")
      end
    end
  end,
})

youdi:addAcquireEffect(function (self, player, is_start)
  if player.phase == Player.NotActive then return end
  local room = player.room
  room.logic:getEventsOfScope(GameEvent.Pindian,999,function (e)
    for _, r in pairs(e.data.results) do
      if r.winner then
        player.room:setPlayerMark(r.winner,"@sj3__youdi-turn","pindianwin")
      end
    end
  end,Player.HistoryTurn)
end)

return youdi